<template>
  <el-container
      class="layout-container-demo"
      style=" border: 1px solid #eee"
  >
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)" >
      <el-row>
        <el-col :span="8" >
          <div class="grid-content bg-purple">
          </div>
        </el-col>
        <el-col :span="16" >
          <div class="grid-content bg-purple-light">
            任务ID
          </div>
        </el-col>
      </el-row>
      <el-scrollbar>
        <el-row v-for="(value,index) in detailedList " :key="index">
          <el-col :span="8" @click="showPicture(value.id); target=value.target.trim().split(',')">
            <div class="grid-content bg-purple">
              {{ index + 1 }}
            </div>
          </el-col>
          <el-col :span="16" @click="showPicture(value.id);target=value.target.trim().split(',')">
            <div class="grid-content bg-purple-light">
              {{ value.id }}
            </div>
          </el-col>
        </el-row>
      </el-scrollbar>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px"
            >
              <setting
              />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>View</el-dropdown-item>
                <el-dropdown-item>Add</el-dropdown-item>
                <el-dropdown-item>Delete</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>Tom</span>
        </div>
      </el-header>

      <el-main>
        <el-card v-for="(value,index) in target" :key="index" >
         {{index + 1}}.target: {{value}}
        </el-card>
        <other-canvas-box :data=picture.data :id=picture.id :target="target" v-if="flag" ></other-canvas-box>
      </el-main>
    </el-container>
  </el-container>

</template>


<script lang="ts" setup>
import {reactive, ref} from 'vue'
import {Setting} from '@element-plus/icons-vue'
import {UserStoreModule} from "@/store/modules/User";
import {IUser} from "@/store/pojo/IUser";
import getDetailedListById from "@/api/task/getList/getDetailedListById";
import getPictureByTaskId from "@/api/task/getPictureByTaskId";
import OtherCanvasBox from "@/components/task/workbench/detailedTask/OtherCanvasBox.vue";


const userInfo: IUser = UserStoreModule.userInfoFromSessionStorage;
const fun = getDetailedListById(userInfo.id);
const detailedList = ref<[]>([]);
const target = ref();
const flag = ref();
flag.value = false;

//保存图片的数据
const picture = reactive({
  data: '',
  id: 0
});

/**
 * 获取 picture 图片
 * @param taskId
 */
const showPicture = (taskId: number) => {
  picture.id = taskId;
  getPictureByTaskId(taskId).then((res) => {
    picture.data = 'data:image/jpeg;base64,' + res.data.data;

    console.log(picture.id)
    flag.value = true;
  }).catch(() => {
    console.log('文件获取失败')
  })
}

//读取当前用户已经接取的任务
fun.then((data) => {
  for (let i = 0; i < data.length; i++) {
    detailedList.value?.push(data[i])
  }

})

</script>

<style scoped>

.layout-container-demo .el-header {
  position: relative;
  background-color: #b3c0d1;
  color: var(--el-text-color-primary);
}

.layout-container-demo .el-aside {
  width: 240px;

  color: var(--el-text-color-primary);
  background: #fff !important;
  border-right: solid 1px #e6e6e6;
  box-sizing: border-box;
}

.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .el-main {
  padding: 0;
}

.layout-container-demo .toolbar {
  position: absolute;
  display: inline-flex;
  align-items: center;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
}


.el-row {
  margin-bottom: 20px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.scrollbar-demo-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
  background: var(--el-color-primary-light-9);
  color: var(--el-color-primary);
}
</style>